package com.boilerCloud.service.device.impl;

import java.util.Calendar;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Service;

import com.boilerCloud.dao.device.DeviceDao;
import com.boilerCloud.dao.device.ProjectDao;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.device.DeviceInfo;
import com.boilerCloud.dto.device.ProjectInfo;
import com.boilerCloud.service.device.IProjectService;
@Service
public class ProjectServiceImpl implements IProjectService {

	@Resource
	private ProjectDao dao;
	
	@Resource
	private DeviceDao devDao;
	
	
	
	@Override
	public void qryList(ProjectInfo pro, HzlqswPage<ProjectInfo> page) throws Exception {
		dao.qryList(pro, page);
		
	}

	@Override
	public void edit(ProjectInfo ProjectInfo)throws Exception {
		dao.edit(ProjectInfo);
		
	}

	@Override
	public void delDevice(int id)throws Exception {
		dao.del(id);
		
	}

	

	@Override
	public DeviceInfo getDeviceInfo(int id) throws Exception {
		// TODO Auto-generated method stub
		return dao.getDeviceInfo(id);
	}
	
	
	
	public void  addProject(ProjectInfo pro) throws Exception {
		
		ProjectInfo projectInfo = dao.qryObjectbynos();
		String nono ="";
		if (projectInfo != null) {
			nono= projectInfo.getProjectNo().substring(4);
		}else
			nono = "10001";
		int year =Calendar.getInstance().get(Calendar.YEAR);
		String projectNo = ""+year+ (Integer.parseInt(nono)+1);
		
		pro.setProjectNo(projectNo);
		int key = dao.add(pro); //获得主键
//		String []devices = pro.getDeviceIds()==null?null:pro.getDeviceIds().split(",");
		ProjectInfo pp = new  ProjectInfo();
		pp.setId(key);
		pp.setProjectNo(projectNo);
		dao.edit(pp);
		
		//绑定选择的设备
		/*for (int i = 0; i < devices.length; i++) {
			DeviceInfo dv = new  DeviceInfo();
			dv.setId(Integer.parseInt(devices[i]));
			dv.setProjectId(key);
			devDao.edit(dv);
		}*/
	}

	/**
	 * <p>Title: qryList2</p>
	 * <p>Description:(一句话阐述): </p>
	 * @param pro
	 * @param page
	 * @author Ran_cc 
	 * @date 2018年3月6日
	 */
	@Override
	public void qryList2(ProjectInfo pro, HzlqswPage<ProjectInfo> page) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * <p>Title: sst</p>
	 * <p>Description:(一句话阐述): </p>
	 * @param w
	 * @return
	 * @author Ran_cc 
	 * @date 2018年3月6日
	 */
	@Override
	public int sst(int w) {
		int s = w;
		return 0;
	}

	/**
	 * <p>Title: getProjectInfo</p>
	 * <p>Description:(一句话阐述):获取单条数据的信息 </p>
	 * @param project
	 * @return
	 * @author Ran_cc 
	 * @throws Exception 
	 * @date 2018年3月8日
	 */
	@Override
	public ProjectInfo getProjectInfo(ProjectInfo project) throws Exception {
		ProjectInfo pro = dao.getProjectInfo(project);
		return pro;
	}

	/**
	 * <p>Title: delProject</p>
	 * <p>Description:(一句话阐述):删除项目数据 </p>
	 * @param id
	 * @author Ran_cc 
	 * @date 2018年3月8日
	 */
	@Override
	public void delProject(int id) {
		dao.del(id);
	}


}
